class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution(object):
    def sumRootToLeaf(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        self.value = 0

        def search(node, v):
            v = (v << 1) + node.val
            if not node.left and not node.right:
                self.value += v
            if node.left:
                search(node.left, v)
            if node.right:
                search(node.right, v)

        search(root, 0)
        return self.value
